package com.hao.wms.mvc;

import com.hao.wms.domain.Depot;
import com.hao.wms.query.DepotQueryObject;
import com.hao.wms.service.IDepotService;
import com.hao.wms.util.RequiredPermission;
import com.opensymphony.xwork2.interceptor.annotations.InputConfig;

import java.io.IOException;

public class DepotAction extends BaseAction{
	/**
	 * 
	 */
	private IDepotService depotService;
	
	
	private Depot depot = new Depot();
	
	public Depot getDepot() {
		return depot;
	}
	public void setDepot(Depot depot) {
		this.depot = depot;
	}
	private DepotQueryObject queryObject = new DepotQueryObject();
	
	
	public DepotQueryObject getQueryObject() {
		return queryObject;
	}
	public void setQueryObject(DepotQueryObject queryObject) {
		this.queryObject = queryObject;
	}
	public void setDepotService(IDepotService depotService) {
		this.depotService = depotService;
	}
	@InputConfig(methodName = "input")
	@RequiredPermission(value="仓库列表")
	public String execute() {
		putContext(PAGERESULT, depotService.query(queryObject));
		
		return LIST;
	}
	@RequiredPermission(value="新增/修改仓库")
	public String input() {
		if(depot.getId()!=null) {
			depot = depotService.get(depot.getId());
		}
		return INPUT;
	}
	@RequiredPermission(value="修改仓库")
	public String saveOrUpdate() {
		try {
			if(depot.getId()!=null) {
                depotService.update(depot);
                addActionMessage("修改成功");
            }else {
                depotService.save(depot);
                addActionMessage("保存成功");
            }
		} catch (Exception e) {
			e.printStackTrace();
			addActionError(e.getMessage());
		}
		return SUCCESS;
	}
	public void prepareSaveOrUpdate(){
		if(depot.getId()!=null) {
			depot = depotService.get(depot.getId());
			
		}
	}
	@RequiredPermission(value="删除仓库")
	public String delete() throws IOException{
		depotService.delete(depot);
		putResponseText("删除成功");
		return NONE;
	}
	
	

}
